# config.py
# 包名为python-dotenv
from dotenv import load_dotenv  # 导入加载环境变量的函数
import os
from urllib import parse

# 使用 python-dotenv 加载环境变量
load_dotenv()


# 设置应用的配置选项
# app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
# app.config['DATABASE_URL'] = os.getenv('DATABASE_URL')

class Config:
    # 使用环境变量设置数据库连接字符串
    SECRET_KEY = os.getenv('SECRET_KEY')
    # SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL')
    HOSTNAME = os.getenv('DBHOSTNAME')
    DBUSERNAME = os.getenv('DBUSERNAME')
    print(DBUSERNAME)
    PASSWORD = os.getenv('PASSWORD')
    # 转义一下密码字符串
    PWD = parse.quote_plus(PASSWORD)
    PORT = os.getenv('PORT')
    DATABASE = os.getenv('DATABASE')
    SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{DBUSERNAME}:{PWD}@{HOSTNAME}:{PORT}/{DATABASE}?charset=utf8mb4"
    # print(SQLALCHEMY_DATABASE_URI)
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 禁用跟踪修改
    DEBUG = True  # 启用调试模式
    # SECRET_KEY = 'your_secret_key'
    # 其他配置选项...
    BASE_DRIP = os.getenv('drip')
    PATHTOKEN = os.getenv("pathtoken")
    DEFAULT_CLIENT_ID = os.getenv("client_id")
    DEFAULT_CLIENT_SECRET = os.getenv("client_secret")
    DEFAULT_GRANT_TYPE = os.getenv("grant_type")
    PATHNOTICE = os.getenv("pathnotice")
    # sjfxpt config
    SJFXPT = os.getenv("SJFXPT")
    # 上传文件路径
    UPLOAD_FOLDER = os.getenv("UPLOAD_FOLDER")
    UPLOAD_COPY_FOLDER = os.getenv("UPLOAD_COPY_FOLDER")
    DOWNLOAD_FOLDER = os.getenv("DOWNLOAD_FOLDER")
    BASE_RPT_DIR = os.getenv("BASE_RPT_DIR")
    # 配置一体化文件上传的路径和复制的路径
    YTH_UPLOAD_FOLDER = os.getenv("YTH_UPLOAD_FOLDER")
    YTH_UPLOAD_COPY_FOLDER = os.getenv("YTH_UPLOAD_COPY_FOLDER")
    YTH_DOWNLOAD_FOLDER = os.getenv("YTH_DOWNLOAD_FOLDER")
    YTH_EXCEL_TEMPLATE = os.getenv("YTH_EXCEL_TEMPLATE")
    # socket base
    S_BASE = os.getenv("S_BASE")

    # XXL-JOB 配置
    XXL_JOB_ADMIN_URL = os.getenv('XXL_JOB_ADMIN_URL')
    XXL_JOB_USERNAME = os.getenv('XXL_JOB_USERNAME')
    XXL_JOB_PASSWORD = os.getenv('XXL_JOB_PASSWORD')

    @property
    def xxl_job_config(self):
        """返回XXL-JOB配置字典"""
        return {
            'xxl_base_url': self.XXL_JOB_ADMIN_URL,
            'username': self.XXL_JOB_USERNAME,
            'password': self.XXL_JOB_PASSWORD
        }

    # cmn
    CAMUNDA_ENGINE_URL = os.getenv('CAMUNDA_ENGINE_URL')

    # 缓存配置
    CACHE_TYPE = os.getenv('CACHE_TYPE')  # 或 'SimpleCache'（开发用）
    CACHE_REDIS_URL = os.getenv('CACHE_REDIS_URL')
    CACHE_DEFAULT_TIMEOUT = os.getenv('CACHE_DEFAULT_TIMEOUT')  # 一般设定5分钟

    # 推荐设置前缀避免冲突
    CACHE_KEY_PREFIX = os.getenv('CACHE_KEY_PREFIX')
    # 如果Redis有密码
    CACHE_REDIS_PASSWORD = os.getenv('CACHE_REDIS_PASSWORD')
    # 性能配置
    # 是否总是查询总数
    ALWAYS_GET_TOTAL = os.getenv('ALWAYS_GET_TOTAL')  # 是否总是查询总数
    # 监控配置
    MONITOR_CACHE_HIT_RATE = os.getenv('MONITOR_CACHE_HIT_RATE')
    MONITOR_RESPONSE_TIME = os.getenv('MONITOR_RESPONSE_TIME')
    CAMUNDA_API_SUCCESS_RATE = os.getenv('CAMUNDA_API_SUCCESS_RATE')

    PATROL_PATH = os.getenv('PATROL_PATH')

